#encoding=utf8
'''
Created on 2012-9-24

@author: Administrator
'''
from DbOperator import DbOperator
from Room import Room
from pub.Config import Config
class RoomModel(DbOperator):
    '''
    房间数据模型
    '''

    
    def __init__(self):
        '''
        Constructor
        '''
        DbOperator.__init__(self)
    def getRoomList(self,SearchCondition,SearchOrderBy,SearchLimit):
        '''
        取得房间列表
        @param Limit:int    请求的条目
        @return: dictionary
        '''
        aParam = {
              Config.S_TABLE:Room.TABLE_NAME,
              Config.S_SEARCHFIELDS:"*",
              Config.S_SEARCHCONDITION:("%s AND "+Room.ROOMISSHOW+"=1")%SearchCondition,
              Config.S_RESULTROW:100,
              Config.S_ORDERBY:SearchOrderBy,
              Config.S_LIMIT:SearchLimit,
          }
        return self.getFieldByCondition(aParam)

    def createNewRoom(self,oRoom):
        '''
        创建一个新的房间
        @param oRoom:Room 
        '''
        pass
    def updateRoom(self):
        pass
    def deleteRoom(self,roomId):
        '''
        根据房间编号删除一个房间
        @param RoomId:int    房间编号
        @return: tuple (ROOMID,ROOM_DELETE_STATE)
        '''
        pass
    def __checkRoomExists(self):
        pass 
    def getRoomIntroById(self,RoomId):
        '''
        根据房间编号返回一个房间对象
        @param roomId: int    房间编号
        @return: Room
        '''
        oRoom = Config.S_SYS_NONE
        if(RoomId):
                aParam = {
                      Config.S_TABLE:Room.TABLE_NAME,
                      Config.S_SEARCHFIELDS:"*",
                      Config.S_SEARCHCONDITION:" `%s`=%s and `%s`=1" % (Room.ROOMID,RoomId,Room.ROOMISSHOW),
                      Config.S_RESULTROW:1,
                  }
                result = self.getFieldByCondition(aParam)
                if(result):
                    oRoom = Room()
                    oRoom.set_id(result[Room.ROOMID])
                    oRoom.set_room_name(result[Room.ROOMNAME])
                    oRoom.set_introduce(result[Room.INTRODUCE])
                    oRoom.set_created(result[Room.CREATED])
                    oRoom.set_first_name(result[Room.ROOMFIRSTNAME])
                    oRoom.set_room_type(result[Room.ROOMTYPE])
                    oRoom.set_room_pri(result[Room.ROOMPRI])
                    oRoom.set_creator(result[Room.CREATOR])
                    oRoom.set_commend(result[Room.COMMEND])
        return oRoom
if __name__=="__main__":
    mRoom = RoomModel()
    oRoom =  mRoom.addRoomToList()
    print oRoom